<?php	
include '../main/main.inc.php';
if(!$session->sesssionExists())
	die("Sessione Inesistente");
	

class Raid extends raid_data 
{
		
	public function __construct()
	{
		parent::__construct();
		
		switch ($_POST['op'])
		{
			case "AjaxGetAllRaidList":
				echo $this->AjaxGetAllRaidList();
			break;
			case "AjaxSetRaid":
				echo $this->AjaxSetRaid();
			break;
			case "AjaxDeleteRaid":
				echo $this->AjaxDeleteRaid();
			break;
			case "AjaxGetRaid":
				echo $this->AjaxGetRaid();
			break;
		}
	}
	
	public function AjaxGetAllRaidList()
	{
		$Raid_data = parent::getAllRaidList();
		$roledata = parent::getAllRoleClean();
		

		
		$raidTable = array('Nome Setup Raid', 'Max Personaggi');
		
		foreach($roledata as $rowRole)
			array_push($raidTable, 'Max '.$rowRole['rolename']);
		
			
		if($Raid_data)
		{
			$elRaidListGrid = new elSimplyGrid();
			$elRaidListGrid->createSimplyGrid('Lista Setup Raid', 'raidlist', $raidTable, 
				$Raid_data,
				el::elButton('elimina_raid','Elimina Setup Raid').el::elS().el::elButton('modifica_raid', 'Modifica Setup Raid')
			);	
			return $elRaidListGrid->elSimplyGrid;
		}
		else
			return null;
	}
	
	public function AjaxSetRaid()
	{
		$roledata = parent::getAllRoleClean();
		$nullRole = FALSE;
		foreach($roledata as $rowRole)
		{
			if(!($_POST['raidmax-'.$rowRole['rolename']] != null))
				$nullRole = TRUE;
				
			$totalRole = $_POST['raidmax-'.$rowRole['rolename']] + $totalRole;
		}
		
		if($_POST['raidname'] != null and $_POST['raidmaxpg']!= null and $nullRole == FALSE)
		{
			if($_POST['raidmaxpg'] < $totalRole)
				return 'Il numero di giocatori totale, '.$_POST['raidmaxpg'].', e\' superiore al totale dei ruoli';
			elseif($_POST['raidmaxpg'] > $totalRole)
				return 'Il numero di giocatori totale, '.$_POST['raidmaxpg'].', e\' Inferiore al totale dei ruoli';
			else
				return parent::setRaid();
		}
		else
			return 'Mancano dei Campi';
	}
	
	public function AjaxDeleteRaid()
	{
		return parent::deleteRaid();
	}
	
	public function AjaxGetRaid()
	{
		return json_encode(parent::getRaid());
	}
}

if($session->sesssionExists())
		$raid = new Raid();
?>